//
//  RuningVC.m
//  K-Music
//
//  Created by 林杰良 on 16/1/4.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "RuningVC.h"
#import "MyAllText.h"

@interface RuningVC ()<UIScrollViewDelegate>{
    
    UIScrollView*myHscrollview;
    
    UIButton * selectedBtn;
    
    UIView*redView;
    
    UIView *firstView;
    
    UIView*secondView;
    
}
@property (strong,nonatomic)UIButton * tmpBtn;


@end

@implementation RuningVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.view.backgroundColor=[UIColor whiteColor];
    [self creatUI];
}
-(void)creatUI{
    NSArray*textData;
    textData=[NSArray arrayWithObjects:@"人气榜",@"礼物榜",@"财富榜",nil];
    myHscrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [myHscrollview setContentSize:CGSizeMake(WIDTH/3, 40)];
    [myHscrollview setShowsHorizontalScrollIndicator:NO];
    [myHscrollview setShowsVerticalScrollIndicator:NO];
    [myHscrollview setDelegate:self];
    myHscrollview.backgroundColor=[UIColor clearColor];
    [self.view addSubview:myHscrollview];
    
    _tmpBtn=nil;
    
    for (int i=0; i<textData.count; i++) {
        UIButton*topBtn=[[UIButton alloc]initWithFrame:CGRectMake(i*WIDTH/3, 1,WIDTH/3-1, 40-2)];
        topBtn.backgroundColor=[UIColor whiteColor];
        [topBtn setTitle:[NSString stringWithFormat:@"%@",textData[i]] forState:UIControlStateNormal];
        [topBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [topBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        topBtn.userInteractionEnabled = YES;
        topBtn.tag=i+100;
        [topBtn addTarget:self action:@selector(TopButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        if ([[MyAllText useIt].clickIt_number intValue]==i) {
            topBtn.selected=YES;
            selectedBtn=topBtn;
            
        }
        
        
        [myHscrollview addSubview:topBtn];
        
    }
    
    
    redView=[[UIView alloc]initWithFrame:CGRectMake(0, 105, WIDTH, HEIGHT-100)];
    redView.backgroundColor=[UIColor grayColor];
    [self.view addSubview:redView];
    
    [self creatTheMusic];
    
    
}

-(void)TopButtonClick:(UIButton*)btn{
    NSString*number=[NSString stringWithFormat:@"%ld",(long)btn.tag];
    int clickNumber=[number intValue]-100;
    NSString*cn=[NSString stringWithFormat:@"%d",clickNumber];
    [MyAllText useIt].clickIt_number=cn;
    selectedBtn.selected = NO;
    btn.selected = YES;
    selectedBtn = btn;
    
    
    if (btn.tag==100) {
        [secondView removeFromSuperview];
        [firstView removeFromSuperview];
        [self creatTheMusic];
        
    }else if(btn.tag==101){
        [secondView removeFromSuperview];
        [firstView removeFromSuperview];
        [self creatTheTopView];
        
    }
    
}


-(void)creatTheMusic{
    
    
    firstView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-100)];
    firstView.backgroundColor=[UIColor redColor];
    [redView addSubview:firstView];
    
    UIScrollView*myscrollview=[[UIScrollView alloc ]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-100)];
    myscrollview.delegate=self;
    myscrollview.contentSize=CGSizeMake(WIDTH, HEIGHT+30);
    
    [firstView addSubview:myscrollview];
    
    
    UIView*aaView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/2)];
    aaView.backgroundColor=[UIColor whiteColor];
    [myscrollview addSubview:aaView];
    
    UILabel *top=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
    top.text=@"人气周榜";
    top.font=[UIFont systemFontOfSize:13.0f];
    [aaView addSubview:top];
    
    
    UIView*h_view_1=[[UIView alloc]initWithFrame:CGRectMake(0, top.frame.size.height+top.frame.origin.y, WIDTH, HEIGHT/2)];
    h_view_1.backgroundColor=[UIColor redColor];
    [aaView addSubview: h_view_1];

    
    for (int i=0; i<4; i++) {
        
        if (i<2) {
            UIView*h_view=[[UIView alloc]initWithFrame:CGRectMake(i*WIDTH/2-1, 1, WIDTH/2-4, HEIGHT/4-5)];
            h_view.backgroundColor=[UIColor whiteColor];
            [h_view_1 addSubview: h_view];
            
            UIImageView*dt=[[UIImageView alloc]initWithFrame:CGRectMake(0, 1,  WIDTH/2-4, HEIGHT/4-3-2)];
            dt.image=[UIImage imageNamed:@"冲榜图片1"];
            [h_view addSubview:dt];
            
            UIImageView *top_img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
            top_img.image=[UIImage imageNamed:@"1."];
            [dt addSubview:top_img];
            
            UILabel*mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/8,  WIDTH/2, 30)];
            mylabel.text=@"Do  you know";
            mylabel.textColor=[UIColor whiteColor];
            
            mylabel.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: mylabel];
            
            
            UILabel*my_name=[[UILabel alloc]initWithFrame:CGRectMake(5, dt.frame.size.height-30, WIDTH/6, 30)];
            my_name.text=@"音乐黑神";
            my_name.textColor=[UIColor whiteColor];
            my_name.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_name];
            
            UILabel*my_fun=[[UILabel alloc]initWithFrame:CGRectMake(my_name.frame.size.width+my_name.frame.origin.x +10, dt.frame.size.height-30, WIDTH/6, 30)];
            my_fun.text=@"1234人";
            my_fun.textColor=[UIColor whiteColor];
            
            my_fun.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_fun];
        }else {
            UIView*h_view=[[UIView alloc]initWithFrame:CGRectMake((i-2)*WIDTH/2-1, HEIGHT/4, WIDTH/2-4, HEIGHT/4-5)];
            h_view.backgroundColor=[UIColor redColor];
            [h_view_1 addSubview: h_view];
            
            UIImageView*dt=[[UIImageView alloc]initWithFrame:CGRectMake(0, 1,  WIDTH/2-4, HEIGHT/4-3-2)];
            dt.image=[UIImage imageNamed:@"冲榜图片1"];
            [h_view addSubview:dt];
            
            UIImageView *top_img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
            top_img.image=[UIImage imageNamed:@"1."];
            [dt addSubview:top_img];
            
            UILabel*mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/8,  WIDTH/2, 30)];
            mylabel.text=@"Do  you know";
            mylabel.textColor=[UIColor whiteColor];
            
            mylabel.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: mylabel];
            
            
            UILabel*my_name=[[UILabel alloc]initWithFrame:CGRectMake(5, dt.frame.size.height-40, WIDTH/6, 30)];
            my_name.text=@"音乐黑神";
            my_name.textColor=[UIColor whiteColor];
            my_name.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_name];
            
            UILabel*my_fun=[[UILabel alloc]initWithFrame:CGRectMake(my_name.frame.size.width+my_name.frame.origin.x +10, dt.frame.size.height-40, WIDTH/6, 30)];
            my_fun.text=@"1234人";
            my_fun.textColor=[UIColor whiteColor];
            
            my_fun.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_fun];
        }

    }
    
//    UIView*secondView2=[[UIView alloc]initWithFrame:CGRectMake(0, h_view_1.frame.size.height+h_view_1.frame.origin.y, WIDTH, HEIGHT/4)];
//    secondView2.backgroundColor=[UIColor grayColor];
//    [aaView addSubview:secondView2];
//    
//    for (int j=0; j<2; j++) {
//        UIView*h_view=[[UIView alloc]initWithFrame:CGRectMake(j*WIDTH/2-1, 1, WIDTH/2-1, HEIGHT/4-20)];
//        h_view.backgroundColor=[UIColor redColor];
//        [secondView2 addSubview: h_view];
//        
//        UIImageView*dt=[[UIImageView alloc]initWithFrame:CGRectMake(0, 1,  WIDTH/2-4, HEIGHT/4-20-1)];
//        dt.image=[UIImage imageNamed:@"组-3"];
//        [h_view addSubview:dt];
//        
//        UIImageView *top_img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
//        top_img.image=[UIImage imageNamed:@"1."];
//        [dt addSubview:top_img];
//        
//        UILabel*mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/8,  WIDTH/2, 30)];
//        mylabel.text=@"Do  you know";
//        mylabel.textColor=[UIColor whiteColor];
//        
//        mylabel.textAlignment=NSTextAlignmentCenter;
//        [dt addSubview: mylabel];
//        
//        
//        UILabel*my_name=[[UILabel alloc]initWithFrame:CGRectMake(5, dt.frame.size.height-30, WIDTH/6, 30)];
//        my_name.text=@"音乐黑神";
//        my_name.textColor=[UIColor whiteColor];
//        my_name.textAlignment=NSTextAlignmentCenter;
//        [dt addSubview: my_name];
//        
//        UILabel*my_fun=[[UILabel alloc]initWithFrame:CGRectMake(my_name.frame.size.width+my_name.frame.origin.x +10, dt.frame.size.height-30, WIDTH/6, 30)];
//        my_fun.text=@"1234人";
//        my_fun.textColor=[UIColor whiteColor];
//        
//        my_fun.textAlignment=NSTextAlignmentCenter;
//        [dt addSubview: my_fun];
//    }
    
    
    UIView*bbView=[[UIView alloc]initWithFrame:CGRectMake(0, aaView.frame.origin.y+aaView.frame.size.height+15, WIDTH, HEIGHT/2)];
    bbView.backgroundColor=[UIColor whiteColor];
    [myscrollview addSubview:bbView];
    
    UILabel *hot=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
    hot.text=@"人气总榜";
    hot.font=[UIFont systemFontOfSize:13.0f];
    [bbView addSubview:hot];
    
    
    UIView*hot_view_1=[[UIView alloc]initWithFrame:CGRectMake(0, top.frame.size.height+top.frame.origin.y, WIDTH, HEIGHT/2)];
    hot_view_1.backgroundColor=[UIColor whiteColor];
    [bbView addSubview: hot_view_1];
    
    for (int a=0; a<4; a++) {
        if (a<2) {
            UIImageView*hot_dt_1=[[UIImageView alloc]initWithFrame:CGRectMake(a*WIDTH/2-1, 1, WIDTH/2-4, HEIGHT/4-5)];
            hot_dt_1.image=[UIImage imageNamed:@"冲榜图片1"];
            [hot_view_1 addSubview:hot_dt_1];
            
            UIImageView*dt=[[UIImageView alloc]initWithFrame:CGRectMake(0, 1,  WIDTH/2-4, HEIGHT/4-3-2)];
            dt.image=[UIImage imageNamed:@"冲榜图片1"];
            [hot_dt_1 addSubview:dt];
            
            UIImageView *top_img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
            top_img.image=[UIImage imageNamed:@"1."];
            [dt addSubview:top_img];
            
            UILabel*mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/8,  WIDTH/2, 30)];
            mylabel.text=@"Do  you know";
            mylabel.textColor=[UIColor whiteColor];
            
            mylabel.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: mylabel];
            
            
            UILabel*my_name=[[UILabel alloc]initWithFrame:CGRectMake(5, dt.frame.size.height-30, WIDTH/6, 30)];
            my_name.text=@"音乐黑神";
            my_name.textColor=[UIColor whiteColor];
            my_name.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_name];
            
            UILabel*my_fun=[[UILabel alloc]initWithFrame:CGRectMake(my_name.frame.size.width+my_name.frame.origin.x +10, dt.frame.size.height-30, WIDTH/6, 30)];
            my_fun.text=@"1234人";
            my_fun.textColor=[UIColor whiteColor];
            
            my_fun.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_fun];

        }else{
           
            UIImageView*hot_dt_1=[[UIImageView alloc]initWithFrame:CGRectMake((a-2)*WIDTH/2-1, HEIGHT/4, WIDTH/2-4, HEIGHT/4-5)];
            hot_dt_1.image=[UIImage imageNamed:@"冲榜图片1"];
            [hot_view_1 addSubview:hot_dt_1];
            
            UIImageView*dt=[[UIImageView alloc]initWithFrame:CGRectMake(0, 1,  WIDTH/2-4, HEIGHT/4-3-2)];
            dt.image=[UIImage imageNamed:@"冲榜图片1"];
            [hot_dt_1 addSubview:dt];
            
            UIImageView *top_img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
            top_img.image=[UIImage imageNamed:@"1."];
            [dt addSubview:top_img];
            
            UILabel*mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/8,  WIDTH/2, 30)];
            mylabel.text=@"Do  you know";
            mylabel.textColor=[UIColor whiteColor];
            
            mylabel.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: mylabel];
            
            
            UILabel*my_name=[[UILabel alloc]initWithFrame:CGRectMake(5, dt.frame.size.height-30, WIDTH/6, 30)];
            my_name.text=@"音乐黑神";
            my_name.textColor=[UIColor whiteColor];
            my_name.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_name];
            
            UILabel*my_fun=[[UILabel alloc]initWithFrame:CGRectMake(my_name.frame.size.width+my_name.frame.origin.x +10, dt.frame.size.height-30, WIDTH/6, 30)];
            my_fun.text=@"1234人";
            my_fun.textColor=[UIColor whiteColor];
            
            my_fun.textAlignment=NSTextAlignmentCenter;
            [dt addSubview: my_fun];

        }
           }
    
    

    
//    UIView*hot_secondView=[[UIView alloc]initWithFrame:CGRectMake(0, hot_view_1.frame.size.height+hot_view_1.frame.origin.y, WIDTH, HEIGHT/4)];
//    hot_secondView.backgroundColor=[UIColor grayColor];
//    [bbView addSubview:hot_secondView];
//    
//    for (int i=0; i<2; i++) {
//        UIView*h_view=[[UIView alloc]initWithFrame:CGRectMake(i*WIDTH/2-1, 1, WIDTH/2-1, HEIGHT/4-20)];
//        h_view.backgroundColor=[UIColor redColor];
//        [hot_secondView addSubview: h_view];
//        
//        UIImageView*dt=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,  WIDTH/2, HEIGHT/4-20)];
//        dt.image=[UIImage imageNamed:@"组-3"];
//        [h_view addSubview:dt];
//        
//        UIImageView *top_img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
//        top_img.image=[UIImage imageNamed:@"1."];
//        [dt addSubview:top_img];
//        
//        UILabel*mylabel=[[UILabel alloc]initWithFrame:CGRectMake(0, HEIGHT/8,  WIDTH/2, 30)];
//        mylabel.text=@"Do  you know";
//        mylabel.textColor=[UIColor whiteColor];
//        
//        mylabel.textAlignment=NSTextAlignmentCenter;
//        [dt addSubview: mylabel];
//        
//        
//        UILabel*my_name=[[UILabel alloc]initWithFrame:CGRectMake(5, dt.frame.size.height-30, WIDTH/6, 30)];
//        my_name.text=@"音乐黑神";
//        my_name.textColor=[UIColor whiteColor];
//        my_name.textAlignment=NSTextAlignmentCenter;
//        [dt addSubview: my_name];
//        
//        UILabel*my_fun=[[UILabel alloc]initWithFrame:CGRectMake(my_name.frame.size.width+my_name.frame.origin.x +10, dt.frame.size.height-30, WIDTH/6, 30)];
//        my_fun.text=@"1234人";
//        my_fun.textColor=[UIColor whiteColor];
//        
//        my_fun.textAlignment=NSTextAlignmentCenter;
//        [dt addSubview: my_fun];
//    }
    
}

-(void)creatTheTopView{
    
    secondView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-100)];
    secondView.backgroundColor=[UIColor clearColor];
    [redView addSubview:secondView];
    
    UIScrollView*myscrollview=[[UIScrollView alloc ]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-100)];
    myscrollview.delegate=self;
    myscrollview.contentSize=CGSizeMake(WIDTH, HEIGHT+60);
    
    [secondView addSubview:myscrollview];
    
    
    
    UILabel *top=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, WIDTH, 30)];
    top.text=@"消费榜";
    top.font=[UIFont systemFontOfSize:13.0f];
    [myscrollview addSubview:top];
    
    
    UIView*mk=[[UIView alloc]initWithFrame:CGRectMake(0,top.frame.size.height+top.frame.origin.y, WIDTH, HEIGHT/2)];
    mk.backgroundColor=[UIColor whiteColor];
    [myscrollview addSubview:mk];
    
    for (int i=0; i<4; i++) {
        
        UIView*mkey=[[UIView alloc]initWithFrame:CGRectMake(0, i*HEIGHT/8, WIDTH, HEIGHT/8)];
        mkey.layer.borderWidth = 0.5;
        mkey.layer.borderColor = [[UIColor blackColor] CGColor];
        [mk addSubview:mkey];
        
        
        UILabel*number=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, 20, HEIGHT/8-10)];
        number.text=[NSString stringWithFormat:@"%d",i];
        [mkey addSubview:number];
        
        UIImageView*Teximage=[[UIImageView alloc]initWithFrame:CGRectMake(number.frame.size.width+10  , 5, 60 , 60)];
        Teximage.layer.masksToBounds = YES;
        Teximage.layer.cornerRadius=40.0f;
        Teximage.image=[UIImage imageNamed:@"me"];
        [mkey addSubview:Teximage];
        
        
        UILabel *Texname=[[UILabel alloc]initWithFrame:CGRectMake(Teximage.frame.size.width+Teximage.frame.origin.x+20, 10, WIDTH/2, 30)];
        Texname.text=@"音乐战队";
        [mkey addSubview:Texname];
        
        UILabel*Texinfo=[[UILabel alloc]initWithFrame:CGRectMake(Teximage.frame.size.width+Teximage.frame.origin.x+20, 40, WIDTH/2, 30)];
        Texinfo.text=@"在房间中消费134599898金币";
        [mkey addSubview:Texinfo];
        
        
        
    }
    
    //------part_two--
    UILabel *moontop=[[UILabel alloc]initWithFrame:CGRectMake(10, top.frame.size.height+top.frame.origin.y+HEIGHT/2, WIDTH, 30)];
    moontop.text=@"收入榜";
    moontop.font=[UIFont systemFontOfSize:13.0f];
    [myscrollview addSubview:moontop];
    
    
    UIView*moon=[[UIView alloc]initWithFrame:CGRectMake(0,moontop.frame.size.height+moontop.frame.origin.y, WIDTH, HEIGHT/2)];
    moon.backgroundColor=[UIColor whiteColor];
    [myscrollview addSubview:moon];
    
    
    
    
    for (int i=0; i<4; i++) {
        
        UIView*mkey=[[UIView alloc]initWithFrame:CGRectMake(0, i*HEIGHT/8, WIDTH, HEIGHT/8)];
        mkey.layer.borderWidth = 0.5;
        mkey.layer.borderColor = [[UIColor blackColor] CGColor];
        [moon addSubview:mkey];
        
        
        UILabel*number=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, 20, HEIGHT/8-10)];
        number.text=[NSString stringWithFormat:@"%d",i];
        [mkey addSubview:number];
        
        UIImageView*Teximage=[[UIImageView alloc]initWithFrame:CGRectMake(number.frame.size.width+10  , 5, 60 , 60)];
        Teximage.layer.masksToBounds = YES;
        Teximage.layer.cornerRadius=40.0f;
        Teximage.image=[UIImage imageNamed:@"me"];
        [mkey addSubview:Teximage];
        
        
        UILabel *Texname=[[UILabel alloc]initWithFrame:CGRectMake(Teximage.frame.size.width+Teximage.frame.origin.x+20, 10, WIDTH/2, 30)];
        Texname.text=@"音乐战队";
        [mkey addSubview:Texname];
        
        UILabel*Texinfo=[[UILabel alloc]initWithFrame:CGRectMake(Teximage.frame.size.width+Teximage.frame.origin.x+20, 40, WIDTH/2, 30)];
        Texinfo.text=@"在包房中获取100000金币";
        [mkey addSubview:Texinfo];
        
        
        
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
